![]() ![]() ![]() ![]() |
GUI Changes: The AWT Grows Up |
With theJTable
class, you can display tables of data.
Think of
JTable
as a viewer of your data.JTable
has no cache of what data it is displaying. You write an object that provides your data toJTable
as the table displays the data. This is done via theEditableTableDataModel
interface. So if as your data values change -- for example, rows are added -- you let the
JTable
know there's new data via one of theTableModelListener
methods. And
JTable
then displays the new info.Here's a little code to set up a table:
// MyData is the object that implements the EditableTableDataModel // interface that you have to write. EditableTableDataModel myDataModel = new MyData(); // Create the table JTable table = new JTable(myDataModel); // Set up the columns of the table for (int columnIndex = 0; columnIndex < NUM_COLUMNS; columnIndex++){ // Create a column object for each column of data JTableColumn newColumn = new JTableColumn("Column "+columnIndex); // The string parameter to JTableColumn needs // to be unique for each column. See Javadoc // of JTableColumn for more info table.addColumn(newColumn); }
![]() ![]() ![]() ![]() |
GUI Changes: The AWT Grows Up |